import request from "@/api";
import { BaseRet, PageQuery, PageRet } from "../response";
import { FormulaVariableTypeEnum } from "@/enums/FormulaVariableTypeEnum";

export default class FormulaVariableApi {
  /**
   * 查询
   * @returns
   */
  static async query(data: FormulaVariableQuery): Promise<PageRet<FormulaVariableModel>> {
    return await request({
      url: "/formulaVariable/query",
      method: "post",
      data: data,
    });
  }

  /**
   * 新增
   * @returns
   */
  static async create(data: FormulaVariableEdit): Promise<BaseRet> {
    return await request({
      url: `/formulaVariable/create`,
      method: "post",
      data: data,
    });
  }

  /**
   * 修改
   * @returns
   */
  static async update(data: FormulaVariableEdit): Promise<BaseRet> {
    return await request({
      url: `/formulaVariable/update`,
      method: "put",
      data: data,
    });
  }

  /**
   * 删除
   * @returns
   */
  static async delete(id: string): Promise<BaseRet> {
    return await request({
      url: `/formulaVariable/delete/${id}`,
      method: "delete",
    });
  }

  /**
   * 查询所有变量
   * @returns
   */
  static async queryFormulaVariable(): Promise<FormulaVariableList[]> {
    return await request({
      url: `/formulaVariable/QueryFormulaVariable`,
      method: "get",
    });
  }

  /**
   * 查询变量类
   * @returns
   */
  static async queryVariableClass(): Promise<FormulaVariableSelect[]> {
    return await request({
      url: `/formulaVariable/QueryVariableClass`,
      method: "get",
    });
  }

  /**
   * 查询变量
   * @returns
   */
  static async queryVariable(value: string): Promise<FormulaVariableSelect[]> {
    return await request({
      url: `/formulaVariable/QueryVariable?variableClass=${value ?? ""}`,
      method: "get",
    });
  }
}

export interface FormulaVariableModel {
  id?: string;
  variableType?: FormulaVariableTypeEnum;
  variableKey?: string;
  variableName?: string;
  entityField?: string;
  entityType?: string;
  variablePrimaryKey?: string;
  order?: number;
}

export interface FormulaVariableQuery extends PageQuery {
  searchString?: string;
}

export interface FormulaVariableEdit {
  id?: string;
  variableType?: FormulaVariableTypeEnum;
  variableKey?: string;
  variableName?: string;
  entityField?: string;
  entityType?: string;
  variablePrimaryKey?: string;
  order?: number;
}

export interface FormulaVariableSelect {
  text?: string;
  value?: string;
}

export interface FormulaVariableList {
  id?: string;
  variableType?: FormulaVariableTypeEnum;
  variableKey?: string;
  variableName?: string;
  entityField?: string;
  entityType?: string;
  variablePrimaryKey?: string;
}
